package junitj2me.framework;

public abstract class TestCase extends Assert implements Test
{
    /**
     * Maguire: More of our poor man's reflect.
     * 
     * Your subclass must implement this method so that TestSuite can know how many of your test1...testN methods have been implemented.
     */
    protected abstract int getNumberOfImplementedTestMethods();

    /**
     * the name of the test case
     * 
     * Maguire: Our big change to support MIDP is that a "name" is actually a "number".
     */
    private int fName;

    public TestCase()
    {
        fName = 0;
    }

    /**
     * Constructs a test case with the given name.
     */
    public TestCase( int name )
    {
        fName = name;
    }

    /**
     * Counts the number of test cases executed by run(TestResult result).
     */
    public int countTestCases()
    {
        return 1;
    }

    /**
     * Creates a default TestResult object
     *
     * @see TestResult
     */
    protected TestResult createResult()
    {
        return new TestResult();
    }

    /**
     * A convenience method to run this test, collecting the results with a
     * default TestResult object.
     *
     * @see TestResult
     */
    public TestResult run()
    {
        TestResult result = createResult();
        run( result );
        return result;
    }

    /**
     * Runs the test case and collects the results in TestResult.
     */
    public void run( TestResult result )
    {
        result.run( this );
    }

    /**
     * Runs the bare test sequence.
     * @exception Throwable if any exception is thrown
     */
    public void runBare() throws Throwable
    {
        Throwable exception = null;
        setUp();
        try
        {
            runTest();
        }
        catch( Throwable running )
        {
            exception = running;
        }
        finally
        {
            try
            {
                tearDown();
            }
            catch( Throwable tearingDown )
            {
                if( exception == null )
                    exception = tearingDown;
            }
        }
        if( exception != null )
            throw exception;
    }

    /**
     * Override to run the test and assert its state.
     * @exception Throwable if any exception is thrown
     */
    protected void runTest() throws Throwable
    {
        runMethod( fName );
    }

    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     */
    protected void setUp() throws Exception
    {
    }

    /**
     * Tears down the fixture, for example, close a network connection.
     * This method is called after a test is executed.
     */
    protected void tearDown() throws Exception
    {
    }

    /**
     * Returns a string representation of the test case
     */
    public String toString()
    {
        return "test" + getName() + " (" + getClass().getName() + ")";
    }

    /**
     * Gets the name of a TestCase
     * @return returns a String
     */
    public int getName()
    {
        return fName;
    }

    /**
     * Sets the name of a TestCase
     * @param name The name to set
     */
    public void setName( int name )
    {
        fName = name;
    }

    /**
     * Maguire: The poor man's reflection.
     *
     */
    public final void runMethod( int aTestNumber )
    {
        switch( aTestNumber )
        {
            case 1:
                test1();
                break;
            case 2:
                test2();
                break;
            case 3:
                test3();
                break;
            case 4:
                test4();
                break;
            case 5:
                test5();
                break;
            case 6:
                test6();
                break;
            case 7:
                test7();
                break;
            case 8:
                test8();
                break;
            case 9:
                test9();
                break;
            case 10:
                test10();
                break;

            case 11:
                test11();
                break;
            case 12:
                test12();
                break;
            case 13:
                test13();
                break;
            case 14:
                test14();
                break;
            case 15:
                test15();
                break;
            case 16:
                test16();
                break;
            case 17:
                test17();
                break;
            case 18:
                test18();
                break;
            case 19:
                test19();
                break;
            case 20:
                test20();
                break;

            case 21:
                test21();
                break;
            case 22:
                test22();
                break;
            case 23:
                test23();
                break;
            case 24:
                test24();
                break;
            case 25:
                test25();
                break;
            case 26:
                test26();
                break;
            case 27:
                test27();
                break;
            case 28:
                test28();
                break;
            case 29:
                test29();
                break;
            case 30:
                test30();
                break;

            default:
                System.out.println( "Unknown TestCase aTestNumber" );
        }

    }

    public void test1()
    {
    }

    public void test2()
    {
    }

    public void test3()
    {
    }

    public void test4()
    {
    }

    public void test5()
    {
    }

    public void test6()
    {
    }

    public void test7()
    {
    }

    public void test8()
    {
    }

    public void test9()
    {
    }

    public void test10()
    {
    }

    public void test11()
    {
    }

    public void test12()
    {
    }

    public void test13()
    {
    }

    public void test14()
    {
    }

    public void test15()
    {
    }

    public void test16()
    {
    }

    public void test17()
    {
    }

    public void test18()
    {
    }

    public void test19()
    {
    }

    public void test20()
    {
    }

    public void test21()
    {
    }

    public void test22()
    {
    }

    public void test23()
    {
    }

    public void test24()
    {
    }

    public void test25()
    {
    }

    public void test26()
    {
    }

    public void test27()
    {
    }

    public void test28()
    {
    }

    public void test29()
    {
    }

    public void test30()
    {
    }
}
